package ztc.servlet;

import ztc.common.UserBean;
import ztc.service.DBUsers;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * Created by ztc on 16-4-8.下午9:24
 */
public class UserRegister extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name=request.getParameter("name");
        String sex=request.getParameter("sex");
        String email=request.getParameter("email");
        String password=request.getParameter("password");
        String qq=request.getParameter("qq");
        String weixin=request.getParameter("weixin");
        String phone=request.getParameter("phone");
        //System.out.println(name+" "+sex+" "+email+" "+password+" "+qq);
        UserBean user=new UserBean(-1,name,sex,email,password,qq,weixin,phone);
        if(new DBUsers().regUser(user)){
            response.sendRedirect("/users/login.jsp？msg="+URLEncoder.encode("注册成功，请登陆。","utf-8"));
        }else{
            response.sendRedirect("/users/register.jsp?msg="+URLEncoder.encode("抱歉注册失败，请重试。","utf-8"));
        }
    }
}
